package com.lx.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        if (method == null || "".equals(method)) {
            req.setAttribute("info", "你怎么不传参数");
        } else {
            if (method.equals("add")) {
                req.setAttribute("info", "执行了add");
            } else if (method.equals("delete")) {
                req.setAttribute("info", "执行了delete");
            } else {
                req.setAttribute("info", "NB");
            }
        }
        req.getRequestDispatcher("index.jsp").forward(req, resp);
        // resp.sendRedirect(req.getContextPath()+"/WEB-INF/msg.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
